var inervalId; //接收进度条时间
var initialopen=1; //初始化  表示第一次打开页面  第一次打开页面时 window窗口还没加载完毕，onSelect()事件直接调用 窗口会报错
var menuId='访单综合管理';
var unionId;

// 注册热键
function registerHotKey(){
    document.onkeydown = function (e) {
        //console.log('键盘按键：', e);
        if(e.key === 'h' && e.ctrlKey === true && e.altKey === true){
            e.preventDefault();
            //console.log('按下了组合键：ctrl+alt+h');
            const data = getKendoGridSelectedRowData();
            console.log('选中的多行数据：', data);
        }
    }
}

// 获取当前所在标签页的序号
function getSelectedIndex() {
    let tab = $('#tabs').tabs('getSelected');
    let index = $('#tabs').tabs('getTabIndex', tab);
    return index;
}
function getCurrentGridId(){// 根据当前选中的 tab 返回表格 id
    const tabIndex = getSelectedIndex();
    if(tabIndex === 0) return 'bill';
    if(tabIndex === 1) return 'bill_finish';
    if(tabIndex === 2) return 'bill_bh';
    return '';
}
// 获取表格选中行(kendoGrid) - 返回数组或者 null
function getKendoGridSelectedRowData(){
    const gridId = getCurrentGridId() ?? '';
    if(gridId.length === 0) return;// 没有获取到表格id则退出

    const kendoGrid = $(`#${gridId}`).data("kendoGrid");
    if( !kendoGrid ) return null;
    const selectedRows = kendoGrid.select();
    if( !selectedRows ) return null;

    let ret = [];
    let selected = Array.from(selectedRows);
    selected.forEach(ele => {
        let data = kendoGrid.dataItem(ele);
        ret.push(data);
    })
    return ret;
}

function downloadFileFromServer(url, fileName) {
    fetch(url)
        .then(response => response.blob())
        .then(blob => {
            const url = window.URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.href = url;
            a.download = fileName || 'downloaded-file';
            document.body.appendChild(a);
            a.click();
            window.URL.revokeObjectURL(url);
            document.body.removeChild(a);
        })
        .catch(console.error);
}
function downloadFile(url, fileName) {
    const a = document.createElement('a');
    a.href = url;
    a.download = fileName || 'downloaded-file';
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
}
function reqFile(fileType){
    // 根据文件类型获取 uri 和文件扩展名
    let uri = '';
    let suffix = '';
    if(fileType === 'word'){
        uri = '/visitorbe/visit/word';
        suffix = 'docx';
    }else{
        uri = '/visitorbe/visit/pdf';
        suffix = 'pdf';
    }

    // 取多选行的第一行 - 一次只下载一个访单的 word 文档
    const selectedRow = getKendoGridSelectedRowData();
    if(!selectedRow || selectedRow.length === 0) return;
    const firstRow = selectedRow[0] ?? {};
    const selectedRowId = firstRow.id ?? 0;
    const url = `${uri}/${selectedRowId}`;

    // 构建下载的文件名
    const { id,visitorCompany,visitorRealName } = firstRow;

    const fn01 = visitorCompany ?? '';
    const fn02 = visitorRealName ?? '';
    const fn03 = id ?? 0;
    const fileName = fn01 + '.' + fn02 + '.' + fn03 + `.${suffix}`;

    $.messager.progress();
    $.ajax({
        type: 'POST', dataType: 'json', contentType: "application/json;charset=UTF-8",
        url: url,
        success: function (res) {
            const { success,msg,data } = res;
            if(!success){
                $.messager.alert('提示', msg, 'warning');
                return
            }
            const { uri } = data;
            const downLoadUri = `https://showawx.xdfznh.club/visitorbe${uri}`;
            downloadFile(downLoadUri,fileName);
        },
        complete: function (XMLHttpRequest, textStatus) {
            $.messager.progress('close');
        }
    });
}


$(function () {
    // 注册热键
    registerHotKey();

    let Strdata = window.sessionStorage.getItem("data");
    unionId= Strdata.split(',')[1];


    //全局 添加自定义请求头
    $.ajaxSetup({
        headers: {"usersid":Strusersid}
    });

    //初始化报表网格
    initKendoUiGrid();
    initKendoUiGrid_unsh();
    initKendoUiGrid_bh();

    setTimeout(function() {
        initialopen=0;
        btn_refresh();

    },100);

});


//查询
function btn_refresh() {
    switch (getSelectedIndex()) {
        case 0:
            btn_refresh_01();
            break;
        case 1:
            btn_refresh_02();
            break;
        case 2:
            btn_refresh_03();
            break;
    }
}


function onSelect(title, index) {
    switch (index) {
        case 0:
            $('#start').datebox('disable');
            $('#end').datebox('disable');
            if (initialopen==0){
                btn_refresh_01();
            }
            break;
        case 1:
            $('#start').datebox('enable');
            $('#end').datebox('enable');
            if (initialopen==0){
                btn_refresh_02();
            }
            break;
        case 2:
            $('#start').datebox('enable');
            $('#end').datebox('enable');
            if (initialopen==0){
                btn_refresh_03();
            }
            break;
    }
}

function btn_refresh_01() {// 第一个标签表格，获取进行中的访单
    var kGrid = getSelectedGrid();
    // $.messager.progress();
    $.ajax({
        url:'https://showawx.xdfznh.club/visitorbe/visit/getVisitInProgress',
        type: 'POST',
        dataType: 'json',
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            console.log(data);
            kGrid.dataSource.data(data);
            $.messager.progress('close');
        },
        complete: function (XMLHttpRequest, textStatus) {
            $.messager.progress('close');
        }
    });
}


function btn_refresh_02() {
    var kGrid = getSelectedGrid();
    var data1 = $('#start').datebox('getValue');
    var data2 = $('#end').datebox('getValue');

    // $.messager.progress();
    $.ajax({
        url:'https://showawx.xdfznh.club/visitorbe/visit/getVisitFinishedProgress',
        type: 'POST',
        dataType: 'json',
        data:JSON.stringify({"sdate":data1,"edate":data2}),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            console.log(data);
            kGrid.dataSource.data(data);
            $.messager.progress('close');
        },
        complete: function (XMLHttpRequest, textStatus) {
            $.messager.progress('close');
        }
    });
}

function btn_refresh_03() {
    var kGrid = getSelectedGrid();
    var data1 = $('#start').datebox('getValue');
    var data2 = $('#end').datebox('getValue');

    // $.messager.progress();
    $.ajax({
        url:'https://showawx.xdfznh.club/visitorbe/call/getRejectVisit',
        type: 'POST',
        dataType: 'json',
        data:JSON.stringify({"sdate":data1,"edate":data2}),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            console.log(data);
            kGrid.dataSource.data(data);
        },
        complete: function (XMLHttpRequest, textStatus) {
            $.messager.progress('close');
        }
    });
}


//获取当前标签页的 网格id
function getSelectedGrid() {
    let kendoGridID = '';
    // kendoGridID = '#bill';
    switch (getSelectedIndex()) {
        case 0:
            kendoGridID = '#bill';
            break;
        case 1:
            kendoGridID = '#bill_finish';
            break;
        case 2:
            kendoGridID = '#bill_bh';
            break;
    }
    return $(kendoGridID).data('kendoGrid');
}

/**
 * 将数组去重
 * @param arr
 * @param attribute
 * @returns {[]}
 */
function unique(arr, attribute) {
    let new_arr = [];
    let json_arr = [];
    for (let i = 0; i < arr.length; i++) {
        if (new_arr.indexOf(arr[i][attribute]) == -1) {
            new_arr.push(arr[i][attribute]);
            json_arr.push(arr[i]);
        }
    }
    return json_arr;
}

// 进行中访单
function initKendoUiGrid() {
    var SUFFIX='_01';
    var visitorNickName = new kendo.data.DataSource({data: []});
    var visitorRealName = new kendo.data.DataSource({data: []});
    var visitorCompany = new kendo.data.DataSource({data: []});
    var category = new kendo.data.DataSource({data: []});
    var remark = new kendo.data.DataSource({data: []});
    var numberOfPeople = new kendo.data.DataSource({data: []});
    var carNumber = new kendo.data.DataSource({data: []});
    var intervieweeRealName = new kendo.data.DataSource({data: []});
    var intervieweeDepartment = new kendo.data.DataSource({data: []});
    var progress = new kendo.data.DataSource({data: []});

    var dataSource = new kendo.data.DataSource({
        pageSize: 200,
        schema: {
            model: {
                fields: {
                    // duration_hour: {type: "number"},
                    // audit_manager_time: {type: "date"},
                }
            }
        },
        aggregate: [
            // {field: "duration_hour", aggregate: "sum"},
        ],
        change: function (e) {
            //获取过滤条件
            let filtrer = this.filter();
            //获取所有数据
            let allData = this.data();
            //进行过滤条件的筛选
            let query = new kendo.data.Query(allData);
            //获取过过滤后的数据
            // let data = query.filter(filtrer).data;
            let data = allData;

            visitorNickName.data(unique(data, 'visitorNickName'));
            visitorRealName.data(unique(data, 'visitorRealName'));
            visitorCompany.data(unique(data, 'visitorCompany'));
            category.data(unique(data, 'category'));
            remark.data(unique(data, 'remark'));
            numberOfPeople.data(unique(data, 'numberOfPeople'));
            carNumber.data(unique(data, 'carNumber'));
            intervieweeRealName.data(unique(data, 'intervieweeRealName'));
            intervieweeDepartment.data(unique(data, 'intervieweeDepartment'));
            progress.data(unique(data, 'progress'));


        },
        requestStart: function (e) {
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text == '查询' || (btn.linkbutton('options').text == '过滤')) {
                    btn.linkbutton('disable')
                }
            })
        },
        requestEnd: function (e) {
            let response = e.response;
            if (response && response['message']) {
                $.messager.show({title: '提示', msg: response['message']})
            }
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text == '查询' || (btn.linkbutton('options').text == '过滤')) {
                    btn.linkbutton('enable')
                }
            })
        }
    });

    let columns=[
        {
            field: "", title: "序号",template: "<span class='row_number'></span>", width: 40
        },
        {field: 'id', title: '主表主键', hidden: true, width: 80,},

        {
            title: "来访信息",
            headerAttributes: {style: 'text-align:center;margin-right: 2px;'},
            columns: [
                {
                    hidden: true,
                    field: 'visitorNickName',
                    title: '微信昵称',
                    width: 80,
                    filterable: false ,
                    // filterable: {multi: true, search: true, dataSource: visitorNickName},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'visitorRealName',
                    title: '真实姓名',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: visitorRealName},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'visitorCompany',
                    title: '公司名称',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: visitorCompany},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'category',
                    title: '来访类型',
                    width: 80,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: category},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'remark',
                    title: '来访缘由',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: remark},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'numberOfPeople',
                    title: '随行人数',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: numberOfPeople},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'carNumber',
                    title: '车牌号',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: carNumber},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'startTime',
                    title: '起始时间',
                    width: 100,
                    filterable: false ,
                    // attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'endTime',
                    title: '终止时间',
                    width: 100,
                    filterable: false ,
                    // attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
            ]
        },
        {
            title: "受访信息",
            headerAttributes: {style: 'text-align:center;margin-right: 2px;'},
            columns: [
                {
                    field: 'intervieweeRealName',
                    title: '受访人员',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: intervieweeRealName},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'intervieweeDepartment',
                    title: '部门',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: intervieweeDepartment},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },

            ]
        },
        {
            field: 'progress',
            title: '进度',
            width: 100,
            // filterable: false ,
            filterable: {multi: true, search: true, dataSource: progress},
            attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
            headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
        },
        {
            field: 'paddingField',
            title: '',
            headerTemplate: '',
            width: 100,
            attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
            headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
        },


    ];
    var grid = $("#bill").kendoGrid({
        sortable: true,
        resizable: true,
        selectable: "multiple row",
        editable: false,
        filterable: true,
        persistSelection: true,
        allowCopy: true,
        title: "报表",
        // columnMenu: {
        //     sortable: true
        // },
        excel: {
            fileName: "进行中访单.xlsx",
            proxyURL: "",
            allPages: true,
            filterable: true
        },
        pageable: {
            pageSize: 200
        },
        dataSource: dataSource,
        columns: columns,
        reorderable: true,
        height: '99%',
        dataBound: function () {  //dataBound 事件在网格数据绑定完成后触发。您可以使用该事件来执行与数据绑定后相关的操作，例如修改数据、设置样式、执行计算等
            var rows = this.items();
            $(rows).each(function () {
                var index = $(this).index() + 1;
                var rowLabel = $(this).find(".row_number");
                $(rowLabel).html(index);
            });
            // var kgrid = $("#bill").data("kendoGrid");    // 行样式
            // let trs = kgrid.tbody.find("tr");
            // trs.each(function (i, row) {
            //     let data = kgrid.dataItem(row);
            //     // let daydiff = data['daydiff'];
            //     let audit_department = data['audit_department_state'];
            //     let audit_factory = data['audit_factory_state'];
            //     let audit_personnel = data['audit_personnel_state'];
            //     let audit_manager = data['audit_manager_state'];
            //
            //     // if (state == 0) $(row).css({"color": "red", "text-decoration": "line-through"});
            //     // if (daydiff < 0) $(row).css({"color": "red"});
            //     if (audit_department === 2 || audit_factory === 2 || audit_personnel === 2 || audit_manager === 2 ) $(row).css({"color": "#0000FF"});
            // });
        },

        columnResize: function (e) {  // 使用 columnResize 事件来监听列调整大小的操作。这个事件会在用户调整列宽时触发
            let field = e.column.field;
            let newWidth = e.newWidth;
            let oldWidth = e.oldWidth;
            // console.log('newWidth:' + newWidth);
            // console.log('oldWidth:' + oldWidth);

            if (newWidth < 20) {
                // $(this).hideColumn(field);
                var grid = $("#bill").data("kendoGrid");
                grid.hideColumn(field);
            } else {
                var Strcolumns={
                    'objectSid':menuId + SUFFIX,
                    "styleList": [{'fieldName':field,'columnWidth':newWidth}]
                };
                $.ajax({
                    url: strLin + 'customTableStyle/updateStyleMult',
                    traditional: true,
                    type: 'POST',
                    dataType: 'json',
                    data: JSON.stringify(Strcolumns),
                    contentType: "application/json;charset=UTF-8",
                    success: function (cdata) {
                        var data=cdata.data;
                        // console.log(data);
                    }
                });
            }
        },
        columnHide: function (e) {  //列隐藏事件
            let field = e.column.field;
            // console.log('隐藏列名:' + field);
            var Strcolumns={
                'objectSid':menuId + SUFFIX,
                "styleList": [{'fieldName':field,'hidden':1}]
            };
            $.ajax({
                url: strLin + 'customTableStyle/updateStyleMult',
                traditional: true,
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(Strcolumns),
                contentType: "application/json;charset=UTF-8",
                success: function (cdata) {
                    var data=cdata.data;
                    // console.log(data);
                }
            });
        },
        columnShow: function (e) {  //列显示事件
            let field = e.column.field;
            var Strcolumns={
                'objectSid':menuId + SUFFIX,
                "styleList": [{'fieldName':field,'hidden':0}]
            };
            $.ajax({
                url: strLin + 'customTableStyle/updateStyleMult',
                traditional: true,
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(Strcolumns),
                contentType: "application/json;charset=UTF-8",
                success: function (cdata) {
                    var data=cdata.data;
                    // console.log(data);
                }
            });
        },
        columnReorder: function (e) {  //  columnReorder 事件来监听列重新排序的操作
            var newColumns = JSON.parse(JSON.stringify(e.sender.columns));
            // console.log(newColumns);
            newColumns = reorder(newColumns, e.oldIndex, e.newIndex);

            var col = [];
            for (let i = 0; i < newColumns.length; i++) {
                if (newColumns[i]['field'])
                    col.push({
                        seq: i,
                        fieldName: newColumns[i]['field'],
                        columnWidth:newColumns[i]['width'],
                        hidden:newColumns[i]['hidden']
                    });
            }

            // console.log(col);

            var Strcolumns={
                'objectSid':menuId + SUFFIX,
                "styleList": col
            };
            $.ajax({
                url: strLin + 'customTableStyle/updateStyleMult',
                traditional: true,
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(Strcolumns),
                contentType: "application/json;charset=UTF-8",
                success: function (cdata) {
                    var data=cdata.data;
                    // console.log(data);
                }
            });
        },
    });

    var grid01 = $('#bill').data('kendoGrid');
    let columnNames = [];
    columns.forEach(item => {
        if (item['field']) {
            columnNames.push(item['field']);
        }
    });
    loadOptions(grid01, columnNames, columns, SUFFIX);
    //双击事件
    grid.on('dblclick', 'tr', function () {
        //  代码
        var kGrid = $("#bill").data("kendoGrid");
        var row = kGrid.select();
        var dataItem = kGrid.dataItem(row);
        var id = dataItem['id'];

        });
    //右击事件
    grid.on('contextmenu', 'tr', function (e) {
        e.preventDefault();
        //  代码
        var menu = '<div id="menu">'
            + '<div data-options="iconCls:\'icon-ok\'">通过审核</div>'
            + '<div data-options="iconCls:\'icon-undo\'">驳回访单</div>'
            + '<div data-options="iconCls:\'icon-clear\'">取消审核</div>'
            + '<div data-options="iconCls:\'icon-ok\'">设置完成</div>'
            + '</div>';
        if ($('#menu').length <= 0) {
            $('body').append(menu);
        }
        $('#menu').menu({
            onClick: function (item) {
                switch (item.text) {
                    case '驳回访单':
                        setaudit(-1);
                        break;
                    case '设置完成':
                        setfinish(1);
                        break;
                    case '通过审核':
                        setaudit(1);
                        break;
                    case '取消审核':
                        setaudit(0);
                        break;

                }
            }
        });
        $('#menu').menu('show', {
            left: e.pageX,
            top: e.pageY
        });
    });
    //  单击事件
    grid.on('click', 'tr', function () {
        //  代码
        // setStatusA('0-1')
        // $('#bt_ll').linkbutton('enable');
        // $('#bt_ll01').linkbutton('enable');

    });
}
//已完成访单
function initKendoUiGrid_unsh() {
    var SUFFIX='_02';
    var visitorNickName = new kendo.data.DataSource({data: []});
    var visitorRealName = new kendo.data.DataSource({data: []});
    var visitorCompany = new kendo.data.DataSource({data: []});
    var category = new kendo.data.DataSource({data: []});
    var remark = new kendo.data.DataSource({data: []});
    var numberOfPeople = new kendo.data.DataSource({data: []});
    var carNumber = new kendo.data.DataSource({data: []});
    var intervieweeRealName = new kendo.data.DataSource({data: []});
    var intervieweeDepartment = new kendo.data.DataSource({data: []});
    var progress = new kendo.data.DataSource({data: []});

    var dataSource = new kendo.data.DataSource({
        pageSize: 200,
        schema: {
            model: {
                fields: {
                    // duration_hour: {type: "number"},
                    // audit_manager_time: {type: "date"},
                }
            }
        },
        aggregate: [
            // {field: "duration_hour", aggregate: "sum"},
        ],
        change: function (e) {
            //获取过滤条件
            let filtrer = this.filter();
            //获取所有数据
            let allData = this.data();
            //进行过滤条件的筛选
            let query = new kendo.data.Query(allData);
            //获取过过滤后的数据
            // let data = query.filter(filtrer).data;
            let data = allData;

            visitorNickName.data(unique(data, 'visitorNickName'));
            visitorRealName.data(unique(data, 'visitorRealName'));
            visitorCompany.data(unique(data, 'visitorCompany'));
            category.data(unique(data, 'category'));
            remark.data(unique(data, 'remark'));
            numberOfPeople.data(unique(data, 'numberOfPeople'));
            carNumber.data(unique(data, 'carNumber'));
            intervieweeRealName.data(unique(data, 'intervieweeRealName'));
            intervieweeDepartment.data(unique(data, 'intervieweeDepartment'));
            progress.data(unique(data, 'progress'));


        },
        requestStart: function (e) {
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text == '查询' || (btn.linkbutton('options').text == '过滤')) {
                    btn.linkbutton('disable')
                }
            })
        },
        requestEnd: function (e) {
            let response = e.response;
            if (response && response['message']) {
                $.messager.show({title: '提示', msg: response['message']})
            }
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text == '查询' || (btn.linkbutton('options').text == '过滤')) {
                    btn.linkbutton('enable')
                }
            })
        }
    });

    let columns=[
        {
            field: "", title: "序号",template: "<span class='row_number'></span>", width: 40
        },
        {field: 'id', title: '主表主键', hidden: true, width: 80,},

        {
            title: "来访信息",
            headerAttributes: {style: 'text-align:center;margin-right: 2px;'},
            columns: [
                {
                    hidden: true,
                    field: 'visitorNickName',
                    title: '微信昵称',
                    width: 80,
                    filterable: false ,
                    // filterable: {multi: true, search: true, dataSource: visitorNickName},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'visitorRealName',
                    title: '真实姓名',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: visitorRealName},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'visitorCompany',
                    title: '公司名称',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: visitorCompany},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'category',
                    title: '来访类型',
                    width: 80,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: category},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'remark',
                    title: '来访缘由',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: remark},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'numberOfPeople',
                    title: '随行人数',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: numberOfPeople},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'carNumber',
                    title: '车牌号',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: carNumber},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'startTime',
                    title: '起始时间',
                    width: 100,
                    filterable: false ,
                    // attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'endTime',
                    title: '终止时间',
                    width: 100,
                    filterable: false ,
                    // attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
            ]
        },
        {
            title: "受访信息",
            headerAttributes: {style: 'text-align:center;margin-right: 2px;'},
            columns: [
                {
                    field: 'intervieweeRealName',
                    title: '受访人员',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: intervieweeRealName},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'intervieweeDepartment',
                    title: '部门',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: intervieweeDepartment},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },

            ]
        },

        {
            field: 'progress',
            title: '进度',
            width: 100,
            // filterable: false ,
            filterable: {multi: true, search: true, dataSource: progress},
            attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
            headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
        },
        {
            field: 'paddingField',
            title: '',
            headerTemplate: '',
            width: 100,
            attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
            headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
        },
    ];
    var grid = $("#bill_finish").kendoGrid({
        sortable: true,
        resizable: true,
        selectable: "multiple row",
        editable: false,
        filterable: true,
        persistSelection: true,
        allowCopy: true,
        title: "报表",
        // columnMenu: {
        //     sortable: true
        // },
        excel: {
            fileName: "已完成访单.xlsx",
            proxyURL: "",
            allPages: true,
            filterable: true
        },
        pageable: {
            pageSize: 200
        },
        dataSource: dataSource,
        columns: columns,
        reorderable: true,
        height: '99%',
        dataBound: function () {  //dataBound 事件在网格数据绑定完成后触发。您可以使用该事件来执行与数据绑定后相关的操作，例如修改数据、设置样式、执行计算等
            var rows = this.items();
            $(rows).each(function () {
                var index = $(this).index() + 1;
                var rowLabel = $(this).find(".row_number");
                $(rowLabel).html(index);
            });
        },

        columnResize: function (e) {  // 使用 columnResize 事件来监听列调整大小的操作。这个事件会在用户调整列宽时触发
            let field = e.column.field;
            let newWidth = e.newWidth;
            let oldWidth = e.oldWidth;
            // console.log('newWidth:' + newWidth);
            // console.log('oldWidth:' + oldWidth);

            if (newWidth < 20) {
                // $(this).hideColumn(field);
                var grid = $("#bill_finish").data("kendoGrid");
                grid.hideColumn(field);
            } else {
                var Strcolumns={
                    'objectSid':menuId + SUFFIX,
                    "styleList": [{'fieldName':field,'columnWidth':newWidth}]
                };
                $.ajax({
                    url: strLin + 'customTableStyle/updateStyleMult',
                    traditional: true,
                    type: 'POST',
                    dataType: 'json',
                    data: JSON.stringify(Strcolumns),
                    contentType: "application/json;charset=UTF-8",
                    success: function (cdata) {
                        var data=cdata.data;
                        // console.log(data);
                    }
                });
            }
        },
        columnHide: function (e) {  //列隐藏事件
            let field = e.column.field;
            // console.log('隐藏列名:' + field);
            var Strcolumns={
                'objectSid':menuId + SUFFIX,
                "styleList": [{'fieldName':field,'hidden':1}]
            };
            $.ajax({
                url: strLin + 'customTableStyle/updateStyleMult',
                traditional: true,
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(Strcolumns),
                contentType: "application/json;charset=UTF-8",
                success: function (cdata) {
                    var data=cdata.data;
                    // console.log(data);
                }
            });
        },
        columnShow: function (e) {  //列显示事件
            let field = e.column.field;
            var Strcolumns={
                'objectSid':menuId + SUFFIX,
                "styleList": [{'fieldName':field,'hidden':0}]
            };
            $.ajax({
                url: strLin + 'customTableStyle/updateStyleMult',
                traditional: true,
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(Strcolumns),
                contentType: "application/json;charset=UTF-8",
                success: function (cdata) {
                    var data=cdata.data;
                    // console.log(data);
                }
            });
        },
        columnReorder: function (e) {  //  columnReorder 事件来监听列重新排序的操作
            var newColumns = JSON.parse(JSON.stringify(e.sender.columns));
            // console.log(newColumns);
            newColumns = reorder(newColumns, e.oldIndex, e.newIndex);

            var col = [];
            for (let i = 0; i < newColumns.length; i++) {
                if (newColumns[i]['field'])
                    col.push({
                        seq: i,
                        fieldName: newColumns[i]['field'],
                        columnWidth:newColumns[i]['width'],
                        hidden:newColumns[i]['hidden']
                    });
            }

            // console.log(col);

            var Strcolumns={
                'objectSid':menuId + SUFFIX,
                "styleList": col
            };
            $.ajax({
                url: strLin + 'customTableStyle/updateStyleMult',
                traditional: true,
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(Strcolumns),
                contentType: "application/json;charset=UTF-8",
                success: function (cdata) {
                    var data=cdata.data;
                    // console.log(data);
                }
            });
        },
    });

    var grid01 = $('#bill_finish').data('kendoGrid');
    let columnNames = [];
    columns.forEach(item => {
        if (item['field']) {
            columnNames.push(item['field']);
        }
    });
    // console.log(columns);
    // console.log(columnNames);
    loadOptions(grid01, columnNames, columns, SUFFIX);

    //双击事件
    grid.on('dblclick', 'tr', function () {
        //  代码
        var kGrid = $("#bill_finish").data("kendoGrid");
        var row = kGrid.select();
        var dataItem = kGrid.dataItem(row);
        var id = dataItem['id'];

    });
    //右击事件
    grid.on('contextmenu', 'tr', function (e) {
        e.preventDefault();
        //  代码
        var menu = '<div id="menu_unsh">'

            + '<div data-options="iconCls:\'icon-no\'">取消完成</div>'
            + '</div>';
        if ($('#menu_unsh').length <= 0) {
            $('body').append(menu);
        }
        $('#menu_unsh').menu({
            onClick: function (item) {
                switch (item.text) {
                    case '取消完成':
                        setfinish(0);
                        break;
                }
            }
        });
        $('#menu_unsh').menu('show', {
            left: e.pageX,
            top: e.pageY
        });
    });
    //  单击事件
    grid.on('click', 'tr', function () {
        //  代码
        // setStatusA('0-1')
        // $('#bt_ll').linkbutton('enable');
        // $('#bt_ll01').linkbutton('enable');

    });
}
//已驳回访单
function initKendoUiGrid_bh() {
    var SUFFIX='_02';
    var visitorNickName = new kendo.data.DataSource({data: []});
    var visitorRealName = new kendo.data.DataSource({data: []});
    var visitorCompany = new kendo.data.DataSource({data: []});
    var category = new kendo.data.DataSource({data: []});
    var remark = new kendo.data.DataSource({data: []});
    var numberOfPeople = new kendo.data.DataSource({data: []});
    var carNumber = new kendo.data.DataSource({data: []});
    var intervieweeRealName = new kendo.data.DataSource({data: []});
    var intervieweeDepartment = new kendo.data.DataSource({data: []});
    var progress = new kendo.data.DataSource({data: []});

    var dataSource = new kendo.data.DataSource({
        pageSize: 200,
        schema: {
            model: {
                fields: {
                    // duration_hour: {type: "number"},
                    // audit_manager_time: {type: "date"},
                }
            }
        },
        aggregate: [
            // {field: "duration_hour", aggregate: "sum"},
        ],
        change: function (e) {
            //获取过滤条件
            let filtrer = this.filter();
            //获取所有数据
            let allData = this.data();
            //进行过滤条件的筛选
            let query = new kendo.data.Query(allData);
            //获取过过滤后的数据
            // let data = query.filter(filtrer).data;
            let data = allData;

            visitorNickName.data(unique(data, 'visitorNickName'));
            visitorRealName.data(unique(data, 'visitorRealName'));
            visitorCompany.data(unique(data, 'visitorCompany'));
            category.data(unique(data, 'category'));
            remark.data(unique(data, 'remark'));
            numberOfPeople.data(unique(data, 'numberOfPeople'));
            carNumber.data(unique(data, 'carNumber'));
            intervieweeRealName.data(unique(data, 'intervieweeRealName'));
            intervieweeDepartment.data(unique(data, 'intervieweeDepartment'));
            progress.data(unique(data, 'progress'));


        },
        requestStart: function (e) {
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text == '查询' || (btn.linkbutton('options').text == '过滤')) {
                    btn.linkbutton('disable')
                }
            })
        },
        requestEnd: function (e) {
            let response = e.response;
            if (response && response['message']) {
                $.messager.show({title: '提示', msg: response['message']})
            }
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text == '查询' || (btn.linkbutton('options').text == '过滤')) {
                    btn.linkbutton('enable')
                }
            })
        }
    });

    let columns=[
        {
            field: "", title: "序号",template: "<span class='row_number'></span>", width: 40
        },
        {field: 'id', title: '主表主键', hidden: true, width: 80,},

        {
            title: "来访信息",
            headerAttributes: {style: 'text-align:center;margin-right: 2px;'},
            columns: [
                {
                    hidden: true,
                    field: 'visitorNickName',
                    title: '微信昵称',
                    width: 80,
                    filterable: false ,
                    // filterable: {multi: true, search: true, dataSource: visitorNickName},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'visitorRealName',
                    title: '真实姓名',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: visitorRealName},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'visitorCompany',
                    title: '公司名称',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: visitorCompany},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'category',
                    title: '来访类型',
                    width: 80,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: category},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'remark',
                    title: '来访缘由',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: remark},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'numberOfPeople',
                    title: '随行人数',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: numberOfPeople},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'carNumber',
                    title: '车牌号',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: carNumber},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'startTime',
                    title: '起始时间',
                    width: 100,
                    filterable: false ,
                    // attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'endTime',
                    title: '终止时间',
                    width: 100,
                    filterable: false ,
                    // attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
            ]
        },
        {
            title: "受访信息",
            headerAttributes: {style: 'text-align:center;margin-right: 2px;'},
            columns: [
                {
                    field: 'intervieweeRealName',
                    title: '受访人员',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: intervieweeRealName},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },
                {
                    field: 'intervieweeDepartment',
                    title: '部门',
                    width: 100,
                    // filterable: false ,
                    filterable: {multi: true, search: true, dataSource: intervieweeDepartment},
                    attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
                    headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
                },

            ]
        },

        {
            field: 'progress',
            title: '进度',
            width: 100,
            // filterable: false ,
            filterable: {multi: true, search: true, dataSource: progress},
            attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
            headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
        },
        {
            field: 'paddingField',
            title: '',
            headerTemplate: '',
            width: 100,
            attributes: {style: 'text-align:center;white-space:nowrap;text-overflow:ellipsis;'},
            headerAttributes: {style: 'text-align:center;margin-right: 2px;'}
        },
    ];
    var grid = $("#bill_bh").kendoGrid({
        sortable: true,
        resizable: true,
        selectable: "multiple row",
        editable: false,
        filterable: true,
        persistSelection: true,
        allowCopy: true,
        title: "报表",
        // columnMenu: {
        //     sortable: true
        // },
        excel: {
            fileName: "已驳回访单.xlsx",
            proxyURL: "",
            allPages: true,
            filterable: true
        },
        pageable: {
            pageSize: 200
        },
        dataSource: dataSource,
        columns: columns,
        reorderable: true,
        height: '99%',
        dataBound: function () {  //dataBound 事件在网格数据绑定完成后触发。您可以使用该事件来执行与数据绑定后相关的操作，例如修改数据、设置样式、执行计算等
            var rows = this.items();
            $(rows).each(function () {
                var index = $(this).index() + 1;
                var rowLabel = $(this).find(".row_number");
                $(rowLabel).html(index);
            });
        },

        columnResize: function (e) {  // 使用 columnResize 事件来监听列调整大小的操作。这个事件会在用户调整列宽时触发
            let field = e.column.field;
            let newWidth = e.newWidth;
            let oldWidth = e.oldWidth;
            // console.log('newWidth:' + newWidth);
            // console.log('oldWidth:' + oldWidth);

            if (newWidth < 20) {
                // $(this).hideColumn(field);
                var grid = $("#bill_finish").data("kendoGrid");
                grid.hideColumn(field);
            } else {
                var Strcolumns={
                    'objectSid':menuId + SUFFIX,
                    "styleList": [{'fieldName':field,'columnWidth':newWidth}]
                };
                $.ajax({
                    url: strLin + 'customTableStyle/updateStyleMult',
                    traditional: true,
                    type: 'POST',
                    dataType: 'json',
                    data: JSON.stringify(Strcolumns),
                    contentType: "application/json;charset=UTF-8",
                    success: function (cdata) {
                        var data=cdata.data;
                        // console.log(data);
                    }
                });
            }
        },
        columnHide: function (e) {  //列隐藏事件
            let field = e.column.field;
            // console.log('隐藏列名:' + field);
            var Strcolumns={
                'objectSid':menuId + SUFFIX,
                "styleList": [{'fieldName':field,'hidden':1}]
            };
            $.ajax({
                url: strLin + 'customTableStyle/updateStyleMult',
                traditional: true,
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(Strcolumns),
                contentType: "application/json;charset=UTF-8",
                success: function (cdata) {
                    var data=cdata.data;
                    // console.log(data);
                }
            });
        },
        columnShow: function (e) {  //列显示事件
            let field = e.column.field;
            var Strcolumns={
                'objectSid':menuId + SUFFIX,
                "styleList": [{'fieldName':field,'hidden':0}]
            };
            $.ajax({
                url: strLin + 'customTableStyle/updateStyleMult',
                traditional: true,
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(Strcolumns),
                contentType: "application/json;charset=UTF-8",
                success: function (cdata) {
                    var data=cdata.data;
                    // console.log(data);
                }
            });
        },
        columnReorder: function (e) {  //  columnReorder 事件来监听列重新排序的操作
            var newColumns = JSON.parse(JSON.stringify(e.sender.columns));
            // console.log(newColumns);
            newColumns = reorder(newColumns, e.oldIndex, e.newIndex);

            var col = [];
            for (let i = 0; i < newColumns.length; i++) {
                if (newColumns[i]['field'])
                    col.push({
                        seq: i,
                        fieldName: newColumns[i]['field'],
                        columnWidth:newColumns[i]['width'],
                        hidden:newColumns[i]['hidden']
                    });
            }

            // console.log(col);

            var Strcolumns={
                'objectSid':menuId + SUFFIX,
                "styleList": col
            };
            $.ajax({
                url: strLin + 'customTableStyle/updateStyleMult',
                traditional: true,
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(Strcolumns),
                contentType: "application/json;charset=UTF-8",
                success: function (cdata) {
                    var data=cdata.data;
                    // console.log(data);
                }
            });
        },
    });

    var grid01 = $('#bill_bh').data('kendoGrid');
    let columnNames = [];
    columns.forEach(item => {
        if (item['field']) {
            columnNames.push(item['field']);
        }
    });
    // console.log(columns);
    // console.log(columnNames);
    loadOptions(grid01, columnNames, columns, SUFFIX);

    //双击事件
    grid.on('dblclick', 'tr', function () {
        //  代码
        var kGrid = $("#bill_bh").data("kendoGrid");
        var row = kGrid.select();
        var dataItem = kGrid.dataItem(row);
        var id = dataItem['id'];

    });
    //右击事件
    grid.on('contextmenu', 'tr', function (e) {
        e.preventDefault();
        //  代码
        var menu = '<div id="menu_bh">'
            + '<div data-options="iconCls:\'icon-no\'">取消驳回</div>'
            + '</div>';
        if ($('#menu_bh').length <= 0) {
            $('body').append(menu);
        }
        $('#menu_bh').menu({
            onClick: function (item) {
                switch (item.text) {
                    case '取消驳回':
                        setaudit(0);
                        break;
                }
            }
        });
        $('#menu_bh').menu('show', {
            left: e.pageX,
            top: e.pageY
        });
    });
    //  单击事件
    grid.on('click', 'tr', function () {
        //  代码
        // setStatusA('0-1')
        // $('#bt_ll').linkbutton('enable');
        // $('#bt_ll01').linkbutton('enable');

    });
}


//列隐藏显示模态窗
function btn_open_column_list() {
    let kGrid = getSelectedGrid();
    let options = kGrid.getOptions().columns;
    if ($('#btn_open_column_list').length <= 0) {
        let div = $(`<div data-options="
                    resizable:true,iconCls:'icon-filter',width:200,height:400,modal:true,title:'列',
                    onClose:function(){$(this).dialog('destroy')}" 
                          class="easyui-dialog" id="btn_open_column_list">
                   </div>`);
        let form = $('<form style="width: 100%;height: 100%;"></form>')
        for (let i of options) {
            if (i.field) {
                let checkbox = $(`<div style="width: 100%;height: auto;padding: 5px;">
                <input class="easyui-checkbox" name="${i.field}" data-options="label:'${i.title}',
                labelWidth:120,value:true,name:'${i.field}'">
                </div>`);
                form.append(checkbox);
            }
        }
        let container = $(`<div></div>`);
        form.appendTo(div);
        div.appendTo(container);
        $('body').append(container);
        $.parser.parse($('#btn_open_column_list').parent());
        let formData = {};
        options.map(item => {
            formData[item['field']] = item['hidden'] == undefined ? true : !item['hidden'];
        })
        $('#btn_open_column_list form').eq(0).form('load', formData);
        $('#btn_open_column_list form .easyui-checkbox').each(function () {
            //  绑定事件
            $(this).checkbox({
                onChange: function (checked) {
                    let opts = $(this).checkbox('options');
                    if (checked) {
                        kGrid.showColumn(opts.name);
                    } else {
                        kGrid.hideColumn(opts.name);
                    }
                }
            })
        })
    } else {
        $('#btn_open_column_list').dialog('open');
    }
}


//  清除过滤
function btn_cancel_filter() {
    let kGrid0 = getSelectedGrid();
    if (kGrid0 != undefined) {
        kGrid0.dataSource.filter({});
    }
}


//导出
function btn_export() {
    // if (!determineQX(menuId,'pexport')){$.messager.alert('提示', '当前登录账号无权限！');return;}
    // $("#bill").data("kendoGrid").saveAsExcel();
    switch (getSelectedIndex()) {
        case 0:
            $("#bill").data("kendoGrid").saveAsExcel();
            break;
        case 1:
            $("#bill_finish").data("kendoGrid").saveAsExcel();
            break;
        case 2:
            $("#bill_bh").data("kendoGrid").saveAsExcel();
            break;
    }
}



//审核
function setaudit(val) {
    // if (!determineQX(menuId,'paudit')){$.messager.alert('提示', '当前登录账号无权限！');return;}
    // if (getSelectedIndex()>0){$.messager.alert('提示','返回有效标签页操作');return;};

    let Strmag;
    if (val===1){Strmag='您确认要审核当前选择访单吗？'
    }else if(val===-1){Strmag='您确认要驳回当前选择的访单吗?'}
    else{Strmag='取消当前访单设置?'}
    $.messager.defaults = {ok: "确定", cancel: "取消", width: 300, closable: false};
    $.messager.confirm('确认', Strmag, function (r) {
        if (r) {
            // var kGrid = $("#bill").data("kendoGrid");
            var kGrid = getSelectedGrid();
            var selectedRows = kGrid.select();
            var selectedDataItems = [];

            for (var i = 0; i < selectedRows.length; i++) {
                var dataItem = kGrid.dataItem(selectedRows[i]);
                selectedDataItems.push(dataItem.id);
            }
            if (selectedDataItems.length>0){
                if (selectedDataItems.length>1){
                    $.messager.alert('提示','不允许选择多行操作！');return;
                }
            }else{
                $.messager.alert('提示','未选择网格数据！');return;
            }

            let Strsql={"unionId":unionId,"id":selectedDataItems[0],"audit":val};

            // 审核：{"unionId":微信用户unionId,"id":访单主键=visit.id,"audit":1}
            // 取消审核：{"unionId":微信用户unionId,"id":访单主键=visit.id,"audit":0}
            // 驳回：{"unionId":微信用户unionId,"id":访单主键=visit.id,"audit":-1}
            // 取消驳回：{"unionId":微信用户unionId,"id":访单主键=visit.id,"audit":0}

            $.ajax({

                url: "https://showawx.xdfznh.club/visitorbe/visit/auditReject",
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(Strsql),
                contentType: "application/json;charset=UTF-8",
                success: function (cdata) {
                    let data=cdata.data;
                    // console.log(cdata);
                    if (cdata.success){
                        btn_refresh();
                        if (val===1){
                            $.messager.show({title: '提示', msg: '审核完成！！！'})
                        }else if (val===-1){
                            $.messager.show({title: '提示', msg: '驳回完成！！！'})
                        }else{
                            $.messager.show({title: '提示', msg: '取消完成！！！'})
                        }
                    }else{
                        $.messager.alert('提示',cdata.msg);
                        return;
                    }
                }
            });

        }
    });

}


//完成设置
function setfinish(val) {
    let Strmag;
    if (val===1){Strmag='您确认要完成当前选择访单吗？'}else{Strmag='您确认要取消已完成的访单吗?'}
    $.messager.defaults = {ok: "确定", cancel: "取消", width: 300, closable: false};
    $.messager.confirm('确认', Strmag, function (r) {
        if (r) {
            var kGrid = getSelectedGrid();
            var selectedRows = kGrid.select();
            var selectedDataItems = [];

            for (var i = 0; i < selectedRows.length; i++) {
                var dataItem = kGrid.dataItem(selectedRows[i]);
                selectedDataItems.push(dataItem.id);
            }
            if (selectedDataItems.length>0){
                if (selectedDataItems.length>1){
                    $.messager.alert('提示','不允许选择多行操作！');return;
                }
            }else{
                $.messager.alert('提示','未选择网格数据！');return;
            }

            let Strsql={"finishedUnionId":unionId,"id":selectedDataItems[0],"finished":val};
            // {"id":3,"finished":【1设置为完工，0取消完工】,"finishedUnionId":"xxxx"}

            $.ajax({
                url: "https://showawx.xdfznh.club/visitorbe/visit/setFinished",
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(Strsql),
                contentType: "application/json;charset=UTF-8",
                success: function (cdata) {
                    let data=cdata.data;
                    // console.log(cdata);
                    if (cdata.success){
                        btn_refresh();
                        if (val===1){
                            $.messager.show({title: '提示', msg: '设置完工成功！！！'})
                        }else{
                            $.messager.show({title: '提示', msg: '取消完工！！！'})
                        }
                    }else{
                        $.messager.alert('提示',cdata.msg);return;
                    }
                }
            });
        }
    });


}

////作废单据
function setstate_zf(val) {

    if (!determineQX(menuId,'pcancel')){$.messager.alert('提示', '当前登录账号无权限！');return;}
    let Strmag;
    if (val===1){Strmag='您确认要恢复当前作废的单据吗？'}else if(val===-1) {Strmag='您确认要删除当前单据吗?'}else{Strmag='您确认要作废当前单据吗?'}
    $.messager.defaults = {ok: "确定", cancel: "取消", width: 300, closable: false};
    $.messager.confirm('确认', Strmag, function (r) {
        if (r) {
            var strData=[];
            var kGrid = getSelectedGrid();
            var selectedRows = kGrid.select();
            var selectedDataItems = [];

            for (var i = 0; i < selectedRows.length; i++) {
                var dataItem = kGrid.dataItem(selectedRows[i]);
                selectedDataItems.push(dataItem.id);
            }
            if (selectedDataItems.length>0){
                if (selectedDataItems.length>1){
                    $.messager.alert('提示','不允许多选！');return;
                }
            }else{$.messager.alert('提示','未选择网格数据！');return;}

            console.log(selectedDataItems);

            var SQLstr = {
                "main": {
                    id:selectedDataItems[0],
                    'state':val,
                },
                "detailList": strData
            };

            console.log(SQLstr);

            $.ajax({
                // headers: {"usersid":Strusersid},
                url: strLin + 'billLeave/save',
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(SQLstr),
                contentType: "application/json;charset=UTF-8",
                success: function (data) {
                    console.log('保存成功data');
                    console.log(data);

                    if (data.code != 1){
                        $.messager.show({title:'提示', msg:data.msg});
                        return;
                    }else {
                        if (val===1){
                            $.messager.show({title: '提示', msg: '恢复作废完成！！！'})
                        }else if (val===-1){
                            $.messager.show({title: '提示', msg: '删除请假完成！！！'})
                        }else{
                            $.messager.show({title: '提示', msg: '作废完成！！！'})
                        }
                        btn_refresh()
                    }
                }
            });

        }
    });
}



/****************************************************************************************** */
  
//关闭当前标签页事件
function closeTab() {
    window.parent.closeTab();
}
function downPdf(){// 下载 pdf 文件

}